package codetop.dp;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class dp134 {
    @Test
    public void test(){
        String s="applepenapple";
        List<String>wodDict=new ArrayList<>();
        wodDict.add("apple");
        wodDict.add("pen");
        new dp134().wordBreak(s,wodDict);
    }
    public boolean wordBreak(String s, List<String> wordDict) {
        boolean dp[]=new boolean[s.length()+1];
        dp[0]=true;
        for (int i = 1; i < s.length()+1; i++) {
            for (String s1 : wordDict) {
               int len=s1.length();
               if (len<=i&&s1.equals(s.substring(i-s1.length(),i))){
                   dp[i]=dp[i-s1.length()]||dp[i];
               }
            }
        }

        return dp[s.length()];
    }
}
